﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Prototype.FetchBall{
public class PlayerControllerX : MonoBehaviour
{
    public GameObject dogPrefab;
    private float spawnInterval = .5f;
    private float nextSpawnTime = 0f;
    private bool canSpawn => nextSpawnTime >= spawnInterval;

    private void Start()
    {
        nextSpawnTime =spawnInterval;
    }
    
    IEnumerator SpawnCoolDown()
    {
        nextSpawnTime = 0;
        while (!canSpawn)
        {
            nextSpawnTime += Time.deltaTime;
            yield return null;
        }
    }

    // Update is called once per frame
    void Update()
    {
        // On spacebar press, send dog
        if (canSpawn && Input.GetKeyDown(KeyCode.Space))
        {
            Instantiate(dogPrefab, transform.position, dogPrefab.transform.rotation);
            StartCoroutine(SpawnCoolDown());
        }
    }
}
}